﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NLite;
using NLite.Interceptor.Mini;
using NLite.Threading;

namespace NLite.Test.IoC
{
    public class TestBase
    {
        private LifecycleLogListner log = new LifecycleLogListner();

        class LifecycleLogListner : NLite.Mini.Listener.ComponentListenerAdapter
        {
            public LifecycleLogListner() : base(ComponentListenStage.PostCreation | ComponentListenStage.PreDestroy) { }

            public override void OnPostCreation(NLite.Mini.Context.IPostCreationContext ctx)
            {
                Console.WriteLine(string.Format("DI container created {0} component", ctx.Instance.GetType().Name));
            }

            public override void OnPreDestroy(IComponentInfo info, object instance)
            {
                Console.WriteLine(string.Format("DI container destroying {0} component", instance.GetType().Name));
            }
          
            
        }

        [SetUp]
        public virtual void Setup()
        {
            ServiceRegistry.Current.ListenerManager.Register(new LifecycleLogListner());
            ServiceRegistry.Register<ProxyFactory>();
           

            Init();
        }

        protected virtual void Init() { }

        [TearDown]
        public void TearDown()
        {
            NLiteEnvironment.Refresh();
        }
    }
}
